package leetcode.editor.cn;

import java.util.*;
import leetcode.editor.common.*;

public class MajorityElement {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {

        // 排序
        public int majorityElement1(int[] nums) {
            Arrays.sort(nums);

         int mid =    nums.length /2;
            int n =nums.length;
            if(nums[mid]==nums[n-1]){
                return nums[mid];
            }
            return 0;
        }



        public int majorityElement2(int[] nums) {
               // 正负电子，  多数派 为 正，  少数派为负    ，正负  对接会发生什么？？
            // 多数派
            int target = 0;
            // 电子状态
            int status=0;

            for (int i = 0; i < nums.length; i++){
                if(status==0){
                    target = nums[i];
                }

                if(target==nums[i]){
                    status++;
                }else {
                    status--;
                }






            }



            return target;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)

    
    public static void main(String[] args) {
        Solution solution = new MajorityElement().new Solution();
        // put your test code here
        solution.majorityElement1(new int[]{1,2,3,2,2,2,5,4,2});
    }
}
